<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>疵点类型映射测试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            text-align: center;
        }
        .flaw-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
            gap: 10px;
            margin-top: 20px;
        }
        .flaw-item {
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            background: #f9f9f9;
        }
        .flaw-type {
            font-weight: bold;
            color: #2196F3;
        }
        .flaw-name {
            color: #666;
        }
        .test-section {
            margin-top: 30px;
            padding: 20px;
            background: #e3f2fd;
            border-radius: 4px;
        }
        .test-input {
            width: 100px;
            padding: 5px;
            margin: 5px;
        }
        .test-result {
            margin-top: 10px;
            padding: 10px;
            background: #fff3e0;
            border-radius: 4px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>疵点类型映射测试</h1>
        
        <div class="flaw-grid" id="flawGrid">
            <!-- 疵点类型将在这里动态显示 -->
        </div>
        
        <div class="test-section">
            <h3>测试疵点类型映射</h3>
            <p>输入疵点类型编号：</p>
            <input type="number" id="testInput" class="test-input" placeholder="输入类型编号">
            <button onclick="testFlawType()">测试</button>
            <div id="testResult" class="test-result" style="display: none;"></div>
        </div>
    </div>

    <script>
        // 疵点类型映射
        const FLAW_TYPE_MAP = {
            0: '停车位',
            1: '横条',
            2: '断头',
            3: '长断头',
            4: '油污',
            5: '漏针',
            6: '其他',
            8: '抛丝',
            9: '吊丝',
            10: '勾丝',
            11: '油污丝',
            12: '导电丝异常',
            13: '毛针',
            14: '其他',
            16: '破洞',
            17: '隐横路',
            18: '坏边右',
            21: '拼缝',
            22: '吊丝',
            23: '色丝（僵丝）',
            24: '盘头印',
            25: '轮胎印',
            26: '叉针',
            27: '钓伤',
            28: '漏针',
            29: '下边',
            33: '毛丝',
            34: '粘丝',
            35: '理边丝',
            37: '盘头毛刺',
            38: '勾丝',
            48: '理直条'
        };

        // 获取疵点类型名称
        function getFlawTypeName(type) {
            return FLAW_TYPE_MAP[type] || `类型${type}`;
        }

        // 渲染疵点类型网格
        function renderFlawGrid() {
            const grid = document.getElementById('flawGrid');
            grid.innerHTML = '';
            
            Object.entries(FLAW_TYPE_MAP).forEach(([type, name]) => {
                const item = document.createElement('div');
                item.className = 'flaw-item';
                item.innerHTML = `
                    <div class="flaw-type">类型 ${type}</div>
                    <div class="flaw-name">${name}</div>
                `;
                grid.appendChild(item);
            });
        }

        // 测试疵点类型映射
        function testFlawType() {
            const input = document.getElementById('testInput');
            const result = document.getElementById('testResult');
            const type = parseInt(input.value);
            
            if (isNaN(type)) {
                result.innerHTML = '<strong>错误：</strong>请输入有效的数字';
                result.style.display = 'block';
                return;
            }
            
            const name = getFlawTypeName(type);
            result.innerHTML = `
                <strong>测试结果：</strong><br>
                类型编号：${type}<br>
                类型名称：${name}<br>
                ${FLAW_TYPE_MAP[type] ? '✅ 已定义' : '❌ 未定义，使用默认名称'}
            `;
            result.style.display = 'block';
        }

        // 页面加载完成后初始化
        document.addEventListener('DOMContentLoaded', function() {
            renderFlawGrid();
            
            // 添加回车键支持
            document.getElementById('testInput').addEventListener('keypress', function(e) {
                if (e.key === 'Enter') {
                    testFlawType();
                }
            });
        });
    </script>
</body>
</html>
